<template>
  <div>
    <van-datetime-picker
  v-model="currentDate"
  type="date"
  title="选择年月日"
  :min-date="minDate"
  :max-date="maxDate"
  @confirm="updateBirthday"
  @cancel="$emit('close')"
/>
  </div>
</template>

<script>
import { updateProfile } from '@/api/user'
import dayjs from 'dayjs'
export default {
  name: 'editName',
  data () {
    return {
      minDate: new Date(1900, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.value)
    }
  },
  props: {
    value: {
      type: String,
      required: true
    }
  },
  components: {},

  computed: {},
  methods: {
    async updateBirthday () {
      this.$toast.loading({
        message: '加载中',
        forbidClick: true,
        duration: 0 // 持续展示 toast
      })
      const currentDates = dayjs(this.currentDate).format('YYYY-MM-DD')
      try {
        await updateProfile({
          birthday: currentDates
        })
        this.$toast.success('修改成功')
        this.$emit('colse')
        this.$emit('input', currentDates)
      } catch (err) {
        this.$toast.success('修改失败')
      }
    }
  }
}
</script>

<style lang='less' scoped>
.box{
    padding: 20px;
}
.van-popup {
  background: red;
}
</style>
